package com.byx.chatclient.factory;

import android.content.Context;

import com.byx.chatclient.manager.ChatRecordManager;
import com.byx.chatclient.manager.DaoManager;
import com.byx.chatclient.manager.UserChatRecordManager;
import com.byx.chatclient.manager.UserGroupManager;
import com.byx.chatclient.manager.UserManager;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * ManagerFactory
 *
 * @author Superb
 * @date 2021/3/25 13:33
 */
public class ManagerFactory {
    private UserChatRecordManager userChatRecordManager;
    private UserManager userManager;
    private UserGroupManager userGroupManager;
    private ChatRecordManager chatRecordManager;

    private static ManagerFactory mInstance;

    private ManagerFactory(){}

    public static ManagerFactory getInstance() {
        if (mInstance == null) {
            synchronized (ManagerFactory.class) {
                if (mInstance == null) {
                    mInstance = new ManagerFactory();
                }
            }
        }
        return mInstance;
    }

    public synchronized ChatRecordManager getChatRecordManager(Context context){
        if (chatRecordManager == null){
            chatRecordManager = new ChatRecordManager(DaoManager.getInstance(context).getDaoSession().getChatPoDao());
        }
        return chatRecordManager;
    }

    public synchronized UserChatRecordManager getUserChatManager(Context context) {
        if (userChatRecordManager == null){
            userChatRecordManager = new UserChatRecordManager(DaoManager.getInstance(context).getDaoSession().getMessagePoDao());
        }
        return userChatRecordManager;
    }

    public synchronized UserManager getUserManager(Context context) {
        if (userManager == null){
            userManager = new UserManager(DaoManager.getInstance(context).getDaoSession().getUserPoDao());
        }
        return userManager;
    }

    public synchronized UserGroupManager getUserGroupManager(Context context){
        if (userGroupManager == null){
            userGroupManager = new UserGroupManager(DaoManager.getInstance(context).getDaoSession().getUserGroupPoDao());
        }
        return userGroupManager;
    }
}
